﻿using System.Security.Cryptography.X509Certificates;

namespace MyCSharpWork3
{
    internal class Program
    {
        //规定格式常量
        const int monthWidth = 35;
        const int monthHeight = 8;
        const int dayWidth = 4;
        /// <summary>
        /// 输出一个日历
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //定初始日期
            DateTime theDay = new DateTime(2022, 1, 1);
            int x = 0, y = 0, theWeekdayofOne = 0;
            do
            {
                //按位置显示月份               
                if (theDay.Day==1)
                {
                    //列
                    x = ((theDay.Month-1)%3)*monthWidth;
                    //行
                    y=(theDay.Month-1)/3*monthHeight;
                    Console.SetCursorPosition(x, y);
                    Console.Write("{0,15}月", theDay.Month);
                    Console.SetCursorPosition(x, y+1);
                    Console.Write("日  一  二  三  四  五  六");
                    //每月一号的星期数
                    theWeekdayofOne=Convert.ToInt32(theDay.DayOfWeek);
                }
                //得到星期几
                int dayofweek = Convert.ToInt32(theDay.DayOfWeek);
                //按位置显示日期                
                Console.SetCursorPosition(x+dayofweek*dayWidth, y+(int)Math.Ceiling((theDay.Day-7+theWeekdayofOne)/7.0)+2);
                Console.Write("{0,2}", theDay.Day);
                //日期加一
                theDay = theDay.AddDays(1);
            } while (theDay.Year==2022);//到2023年就结束
            Console.ReadKey();
        }
    }
}